Bitwise Calculator

See AND, OR, XOR, NOT and shift operations in binary

A in binary
B in binary
Result (AND)
Decimal
Hex

What this tool does

Computes AND, OR and XOR of two integers, NOT of one, and left and right shifts, showing inputs and result side by side in binary, decimal and hexadecimal. For bit masks and flags, permission bits, checking programming homework, or subnet arithmetic.

How it is calculated

It uses JavaScript's 32-bit integer operators directly. AND (&) gives 1 where both bits are 1, OR (|) where either is 1, XOR (^) where they differ, and NOT (~) flips every bit. Left shift (<<) multiplies by 2ⁿ; right shift (>>) divides by 2ⁿ, keeping the integer part. The binary display width follows the largest absolute value among A, B and the result, starting at 8 bits and growing in steps of 4 up to 32. It opens with A = 12 and B = 10, so 1100 AND 1010 = 1000, which is 8 in decimal and 0x8 in hex. With the same values OR gives 14 (0xE) and XOR gives 6 (0x6).

  • Choose an operation: AND · OR · XOR · NOT · << · >>
  • Enter decimal integers in A and B (NOT uses only A)
  • Read the binary rows to see how each bit position combined
  • The result is also shown in decimal and 0x-prefixed hexadecimal
  • The result updates as soon as you edit a number, so there is no calculate button

Things to know

  • Testing a flag: (value AND mask) is non-zero when that bit is set. Example: permission 6 (110₂) AND 2 (010₂) = 2 → write permission present.
  • Clearing a flag: value AND NOT mask. Toggling: value XOR mask; XOR twice restores the original.
  • x << 1 is x × 2 and x >> 1 is the integer part of x ÷ 2, a quick way to multiply or divide by powers of two.
  • A negative NOT result is normal: in 32-bit two's complement, ~5 = −6. The hex row shows the unsigned form 0xFFFFFFFA.
  • Only shift counts (B) from 0 to 31 are meaningful. JavaScript uses B modulo 32, so 1 << 32 is 1, not 2³².
  • For negative inputs the binary rows show only the low bits of the two's complement, cut to the display width. Check the hex result for the full 32-bit pattern.
  • It works for subnet maths if you enter one IP octet (0–255) at a time, for example 192 AND 255 = 192 and 168 AND 0 = 0, applying the mask octet by octet.

Frequently asked questions

Why is NOT 5 equal to −6?

Flipping every bit of a 32-bit integer gives −(x + 1) under two's complement. To see it as 8 bits, AND the result with 255: 250.

What happens to negatives in a right shift?

It is an arithmetic shift (>>) that keeps the sign bit, so −8 >> 1 = −4. The unsigned shift (>>>) is not offered here.

Can I use numbers larger than 32 bits?

No. JavaScript bitwise operators truncate to 32 bits, so values above 2,147,483,647 give wrong results.

Can I enter hex or binary?

The inputs accept decimal only. Convert 0xFF to 255 or 1010₂ to 10 first. Any fractional part is dropped, and the result is shown in binary, decimal and hex.

← na.to home